package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Project;
import com.kaishengit.entity.User;
import com.kaishengit.service.DocumentService;
import com.kaishengit.util.web.ServletUtil;

public class DocumentNew extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletUtil.forword(request, response, "document/new_document");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		User user = (User) ServletUtil.getSession(request).getAttribute("curr_user");
		Project project = (Project) ServletUtil.getSession(request).getAttribute("curr_project");
		new DocumentService().save(title,content,user,project);
		
		ServletUtil.redirect(response, "document.jspx");
		
	}

}
